home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / swagd_f.zip / DOS.SWG / 0083_DOS Redirection of text.pas < prev    next >
Pascal/Delphi Source File  |  1995-03-03  |  1KB  |  59 lines

  1. {
  2.  MH> Could anyone know how to redirect a standard output (CRT) to a file using
  3.  MH> standard Write/WriteLn(Output,...) Pascal procedures ?
  4.  
  5. I was playing around with this about two hours and i still didn't figure out
  6. how to construct my program so Crt standard write and writeln procedures would
  7. write depending on which device you specified in the command line.
  8.  
  9. So i left idea to trouble myself more and wrote my own dependent write
  10. procedures that will print only string-typed variables, but at least can be
  11. redirected to any other device than CONsole device. :)
  12.  
  13. Now my code goes:
  14.  
  15. {---cut here---}
  16.  
  17. Program SupportingRedirectionWithCrt;
  18. { Public Domain, by Andrew Eigus }
  19.  
  20. uses Crt;
  21.  
  22. Procedure DevWrite(Str : string); assembler;
  23. { Device-dependent write procedure }
  24. Asm
  25.   push ds
  26.   lds si,Str
  27.   cld
  28.   xor ax,ax
  29.   lodsb
  30.   mov cx,ax
  31.   mov dx,si
  32.   mov bx,1 { standard output device }
  33.   mov ah,40h
  34.   int 21h
  35.   pop ds
  36. End; { DevWrite }
  37.  
  38. Procedure DevWriteLn(Str : string); assembler;
  39. { Device-dependent writeln procedure }
  40. Asm
  41.   les si,Str
  42.   push es
  43.   push si
  44.   call DevWrite
  45.   mov ah,02h
  46.   mov dl,0Dh
  47.   int 21h
  48.   mov dl,0Ah
  49.   int 21h
  50. End; { DevWriteLn }
  51.  
  52. Begin
  53.   DevWriteLn('Hello, world!'#13#10);
  54.   DevWriteLn('This text might be freely redirected to any device from the');
  55.   DevWriteLn('command line.');
  56.   WriteLn(#13#10'And this text may appear on screen only.')
  57. End.
  58.  
  59.